import { buildUrl, supplyUrl, roadUrl } from "@/config/index"
import disLine10kv from "../geojson/10kVLine.json"
import infoBox from '@/plugins/toolsManage/infoWindow/infoWindow'

const disLine = function(viewer, Cesium) {
    var self = this
    this.viewer = viewer
    this.Cesium = Cesium
    this.infoWindow = new infoBox(viewer)
    this.colorMap = {
        "天顶变": this.Cesium.Color.fromCssColorString('#1aa').withAlpha(0.8),
        "麓龙变": this.Cesium.Color.fromCssColorString('#a11').withAlpha(0.8),
        "望城坡变": this.Cesium.Color.fromCssColorString('#11a').withAlpha(0.8),
        "金谷变": this.Cesium.Color.fromCssColorString('#155').withAlpha(0.8),
        "桐梓坡变": this.Cesium.Color.fromCssColorString('#515').withAlpha(0.8),
        "石岭塘变": this.Cesium.Color.fromCssColorString('#551').withAlpha(0.8),
        "西站变": this.Cesium.Color.fromCssColorString('#aa1').withAlpha(0.8),
        "谭石变": this.Cesium.Color.fromCssColorString('#116').withAlpha(0.8),
        "游园东变": this.Cesium.Color.fromCssColorString('#1aa').withAlpha(0.8),
        "湘岳南变": this.Cesium.Color.fromCssColorString('#3fd').withAlpha(0.8)
    }
    this.selectLine = null
    this.RoadMap = new Map();

}
disLine.prototype = {
    init() {
        let self = this
            var promise = self.Cesium.GeoJsonDataSource.load("/static/geojson/Line.json", { clampToGround: true});
            promise.then(function(dataSource) {
                self.viewer.dataSources.add(dataSource);
                var entities = dataSource.entities.values;
                for (var i = 0; i < entities.length; i++) {
                    var entity = entities[i];
                    console.log(entity._properties.Name._value)
                    self.RoadMap.set(entity._properties.Name._value,entity)
                    // entity.show = false
                    // if(entity._properties.GuiShu._value == "西站变" || entity._properties.GuiShu._value == "望城坡变"){
                    //     entity.show = true
                    // }
                    entity.polyline.width = 4
                    let lineColor = self.colorMap[entity._properties.GuiShu._value]
                    entity.polyline.material = new self.Cesium.PolylineTrailLinkMaterialProperty(lineColor || self.Cesium.Color.fromCssColorString('#03D07A').withAlpha(0.8), 3000)
                    entity.defaultMaterial = new self.Cesium.PolylineTrailLinkMaterialProperty(lineColor || self.Cesium.Color.fromCssColorString('#03D07A').withAlpha(0.8), 3000)
                    entity.click = function(et) {
                            var tempPoup = `<div class="infolist"><span >线路名称:${et._properties.Name._value}</span></div>`
                            self.infoWindow.show(et._properties.Name._value, tempPoup, et._properties.GuiShu._value)
                    }
                    // new self.Cesium.PolylineGlowMaterialProperty({
                    //     glowPower : 0.3,
                    //      color : lineColor || self.Cesium.Color.BLUE.withAlpha(0.9),
                    // })
            }
        });
    },
    selectLineByName(name){
        let line = this.RoadMap.get(name)
        var tempPoup = `<div class="infolist"><span >线路名称:${line._properties.Name._value}</span></div>`
        this.infoWindow.show(line._properties.Name._value, tempPoup, line._properties.GuiShu._value)

        return line
    },
    hide() {

    },
    show(id) {

    },
    goto(id) {

    },
    guid() {
        function S4() {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        }

        return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    }

}

export default disLine